define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'procurement.product_maps/index',
        add_url: 'procurement.product_maps/add',
        edit_url: 'procurement.product_maps/edit',
        delete_url: 'procurement.product_maps/delete',
        export_url: 'procurement.product_maps/export',
        modify_url: 'procurement.product_maps/modify',

        import_url:'procurement.productMaps/import',

        export_template:'procurement.productMaps/export_template',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add', 'delete', 'import',
                    [{
                        text: '导入',
                        url: init.import_url,
                        method: 'open',
                        auth: 'import',
                        class: 'layui-btn layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="true"',
                    }], 'export'],

                // toolbar: [
                //     'refresh', 'add', 'delete','export',
                //     [{
                //         text: '货号模板导出',
                //         url: init.export_template,
                //         method: 'open',
                //         auth: 'export_template',
                //         class: 'layui-btn layui-btn-sm',
                //         icon: 'fa fa-plus ',
                //         extend: 'data-full="true"',
                //     }] ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '主键'},
                    {field: 'item_number', title: '工厂货号'},
                    {field: 'sku', title: 'SKU',search:'batch'},
                    {field: 'name', title: '名称'},
                    {field: 'supplier.name', title: '供应商'},
                    {field: 'category.name', title: '分类'},
                    {field: 'rule.name', title: '规则'},
                    {field: 'is_auto', title: '是否自动分配'},
                    {field: 'cost', title: '成本价格'},
                    {field: 'cycle', title: '生成周期（天）'},
                    {field: 'ai_category_id', title: 'AI分类ID'},
                    {field: 'ai_multiple', title: 'AI制作倍数'},
                    {field: 'extension', title: '扩展'},
                    {field: 'create_time', title: '创建时间'},
                    {width: 250, title: '操作', templet: ea.table.tool},

                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        import: function () {
            // 初始化分区上传
            var params = { id: 'upload-file', url: init.import_url, type: 0 };
            ea.file.upload(params);

            // 选项卡监听上传
            var element = layui.element;
            element.on('tab(table-box)', function (data) {
                console.log(data);
                var id = $('.layui-show').find('.upload-file').attr('id');
                params.id = id;
                params.type = data.index;
                ea.file.upload(params);
            });

        },
    };
    return Controller;
});